package history.hot100;

import java.util.HashSet;
import java.util.Set;

// 128. 最长连续序列
public class LeetCode_128 {
    public int longestConsecutive(int[] nums) {
        Set<Integer> set = new HashSet<>();
        for (int num: nums) set.add(num);
        int res = 0;
        for (int num: nums) {
            if (set.contains(num-1)) continue;
            int len = 0;
            while (set.contains(num++)) len++;
            res = Math.max(res, len);
        }
        return res;
    }
}
